The Bundle Resource
A bundle is a resource that associates all of the resources used by the Finder for your application; in particular, it associates your application and its
documents with their icons. The bundle resource ('BNDL') contains
• the application's signature and the resource ID of its signature resource (which should always be 0)
• the assignment of local IDs to the resource IDs of all 'ICN#' resources
defined for the application
• the assignment, for compatibility reasons, of local IDs to 'FREF'
resourceIDs (For consistency, these can be the same local IDs that are
assigned inside the 'FREF' resources, but they do not have to be-they
only need to be unique for every 'FREF' resource.)
When the Finder first displays your application on the user's desktop, it your application has a bundle. If it does not, the Finder displays the default icons shown in the figure in Icon Resources. If your application has a bundle, the Finder installs the information from the 'BNDL' resource and all its bundled resources into either the desktop database for a hard disk or into the
Desktop file for a floppy disk and uses this information to display icons for the
file types associated with your application.
You must assign local IDs to your 'ICN#' resources within your 'BNDL'
resource. Make sure that for all your file types with icons, these local IDs
match the local IDs you assigned inside their corresponding 'FREF' resources. In
the Desktop file on floppy disks (and on hard disks running earlier versions of
system software), the Finder re numbers the resource ID's that you've assigned to your resources to avoid conflicts with the resources of other
applications. Therefore, the bundle has to rely on these local IDs to map icon
list resources to their file reference resources; that is, the 'BNDL' resource uses the local ID you assign to an 'ICN#' resource to map it to the
'FREF' resource that has the same local ID assigned inside itself.
For example, the 'FREF' resource with resource ID 208 in the code shows that
the file type 'APPL' (the application file) is assigned a local ID of 0. In the
'BNDL' resource shown in the following code listing, you see that local ID 0 is
assigned to the 'ICN#' resource with resource ID 128. This maps the icon
defined by this resource (see the third figure in Icon Resources) to the application file. The following code shows the bundle resource for the icons and
'FREF' resources defined in the last two code examples. (in Icon Resources and Using a bundle resource
resource 'BNDL' (128, purgeable) { /* bundle resource ID */ 'WAVE', /* signature */
0, /* resource ID of signature resource: should be 0 */
{
'ICN#', /* mapping local IDs in 'FREF's to 'ICN#' IDs */
{
0, 128, /* 'FREF' with local ID 0 maps to 'ICN#' res ID 128 */
1, 129, /* 'FREF' with local ID 1 maps to 'ICN#' res ID 129 */
2, 130, /* 'FREF' with local ID 2 maps to 'ICN#' res ID 130 */
3, 131 /* 'FREF' with local ID 3 maps to 'ICN#' res D 131 */
/* no 'FREF' with local ID 4 in this list: */
/* TeachText's icons used for 'ttro' file type */
},
'FREF', /* local resource IDs for 'FREF's: no duplicates */
{
10, 208, /* local ID 10 assigned to 'FREF' res ID 208 */
11, 209, /* local ID 11 assigned to 'FREF' res ID 209 */
12, 210, /* local ID 12 assigned to 'FREF' res ID 210 */
13, 211, /* local ID 13 assigned to 'FREF' res ID 211 */
14, 212 /* local ID 14 assigned to 'FREF' res ID 212 */
}
}
};
Notice that you also assign local IDs to 'FREF' resources inside the 'BNDL'
resource. This assignment is superfluous because the Finder does not map these local IDs to any other resources. The local ID assignment for 'FREF'
resources inside the bundle was implemented for the earliest versions of
Macintosh system software, and it remains this way today to maintain backward
compatibility. For compatibility with the format of the 'BNDL' resource,
assign local IDs to 'FREF' resource IDs. You may number them any way you
like, except that each local ID in this particular list must be unique.
Of all the icon resource types that make up an icon family, you need to list
only the 'ICN#' resource in the 'BNDL' resource. The Finder automatically recognizes and loads all the other members of the icon family.
If the user drags documents created by other applications to your application
icon, and if you have created 'FREF' resources for these documents' file types,
the Finder launches your application and passes it the names of the documents. You should create 'FREF' resources for all file types that your
application supports. Do not provide icon resources for file types created by
other applications because the Finder will not use them, but will instead use the icon resources defined by the documents' creators. Though the local IDs of
such an 'FREF' resource are superfluous in the 'FREF' resource and at the
bottom of the 'BNDL' resource, the resource formats require that you provide
local IDs in both.
For example, notice in the code example in Icon Resources that the 'FREF' resource with resource ID 212 is assigned a local ID of 4, but that no 'ICN#'
resource is assigned to local ID 4 in the 'BNDL' resource in the code example in
file type of 'ttro', was created to make the Finder launch the sample application when users drag TeachText read-only documents to the
application icon. No icon mapping is made for this file type in the sample
application's bundle because the Finder displays the icons defined for it by the TeachText application. The 'FREF' resource with resource ID 212 is
assigned to local ID 14 in the 'BNDL' resource in this code because the format
of the resource requires a local ID for all 'FREF' associated resources.
You alert the Finder that your application has a bundle resource by setting a bit in the file's Finder flags field. (Most development environments provide a simple tool for setting the bundle bit. Finder flags are described in the The following figure illustrates how the bundle resource created in this
program example uses local IDs to map icon list resources to
file reference resources.
This illustrates two main concepts: first, that one bundle ties together all the
icon resources and file reference resources for your application and all of its
documents; and second, that the icon resources and their associated
file reference resources are mapped together by local IDs. In this figure, the
application file's 'ICN#' resource has resource ID 128 while its 'FREF'
resource has resource ID 208. For maintainability, you should probably
assign the same resource ID to a file's 'FREF' resource that you assigned to its
'ICN#' resource. However, because the Finder re numbers these whenever it adds them to a Desktop file, you must map them by using local IDs. In the
figure above, the application file's 'ICN#' resource is assigned local ID 0. This
maps the icon to the file type described by the 'FREF' resource with local ID
0-in this case, the 'FREF' resource with resource ID 208.
This figure also illustrates the general steps you must take to provide icons
for applications and documents. These steps are enumerated here in more
detail and assume that you are using a tool, such as ResEdit, that allows you to
open and edit several resources simultaneously. (Remember that these
resources must have resource ID's of 128 or greater.)